package com.txl.mycamera.ui;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.txl.mycamera.R;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.zhihu.matisse.internal.entity.CaptureStrategy;

import java.io.File;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * @ProjectName: MyCamera
 * @Package: com.txl.mycamera.ui
 * @ClassName: MenuActivity
 * @Description: java类作用描述
 * @Author: Tao.xiaolong
 * @CreateDate: 2021-04-25 22:01
 * @UpdateUser: 更新者：
 * @UpdateDate: 2021-04-25 22:01
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */
public class MenuActivity extends AppCompatActivity {
    private static final String TAG = "MenuActivity";

    ImageView imageView;
    Button button;
    private static final int REQUEST_CHOOSE_CODE = 100;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        initViews();
    }
    private void initViews(){
        imageView = findViewById(R.id.image_view);
        button = findViewById(R.id.choose);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Matisse.from(MenuActivity.this).choose(MimeType.ofAll())
                        .maxSelectable(1)
                        .countable(true)
                        .captureStrategy(new CaptureStrategy(true,"com.txl.mycamera.utils.MyFileProvider"))
                        .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
                        .imageEngine(new GlideEngine())
                        .forResult(REQUEST_CHOOSE_CODE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d(TAG,"onActivityResult requestCode="+requestCode+",resultCode="+resultCode);
        if (requestCode==REQUEST_CHOOSE_CODE && resultCode == RESULT_OK){
            String path = Matisse.obtainPathResult(data).get(0);
            Log.d(TAG,"onActivityResult Path:"+path);
            Glide.with(MenuActivity.this).load(new File(path)).into(imageView);
        }
    }
}
